<?php
namespace Org\Util;
class Step{
	//循环后台分类列表
	Static public function fenlei($step, $log="&nbsp&nbsp&nbspㄴ" ,$pid=0, $level=0){
		$arr = array();
		foreach($step as $v){
			if($v['pid'] == $pid){
				$v['level'] = $level+1;
				$v['log'] = str_repeat($log,$level);
				$arr[] = $v;
				$arr = array_merge($arr, self::fenlei($step, $log, $v['id'], $levle+1));
			}
		}
		return $arr;
	}	
	//展示前台分类列表
	Static public function showfenlei($step,$name='child',$pid=0){
		$arr = array();
		foreach($step as $v){
			if($v['pid'] == $pid){
				$v['child'] = self::showfenlei($step,$name,$v['id']);
				$arr[] = $v;
			}
		}
		return $arr;		
	}	
	//获取高级别列表,获取目前所在位置,返回所有父级分类
	Static public function getparents($step,$id){
		$arr = array();
		foreach($step as $v){
			if($v['id'] == $id){
				$arr[] = $v;
				//反过来即可倒换顺序
				$arr = array_merge(self::getparents($step, $v['pid']),$arr);				
			}			
		}	
		return $arr;
	}	
	//获取子孙树的id	
	Static public function getchild($step,$id){
		$arr = array();		
		foreach($step as $v){
			if($v['pid'] == $id){
				$arr[] = $v['id'];
				$arr = array_merge($arr,self::getchild($step, $v['id']));
			}			
		}		
		return $arr;
	}	
}
?>